//
//  RadiusImageView.m
//  Jewelry
//
//  Created by 中企互联 on 2017/10/24.
//  Copyright © 2017年 中企互联. All rights reserved.
//

#import "RadiusImageView.h"

@implementation RadiusImageView

+ (UIImageView *)bgImageViewWith:(CellType)type bgImageViewWithFrame:(CGRect)frame oneRadius:(CGFloat)one twoRadius:(CGFloat)two cellBgColor:(UIColor *)clolor {
    UIImageView * cellBackView = [[UIImageView alloc] initWithFrame:frame];
    cellBackView.backgroundColor = clolor;
    
    switch (type) {
        case Normal:
        {
            
        }
            break;
        case Singel:
        {
            UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cellBackView.bounds cornerRadius:one];
            CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
            maskLayer.frame = cellBackView.bounds;
            maskLayer.path = maskPath.CGPath;
            cellBackView.layer.mask = maskLayer;
        }
            break;
        case TopFillet:
        {
            UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cellBackView.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(one, two)];
            CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
            maskLayer.frame = cellBackView.bounds;
            maskLayer.path = maskPath.CGPath;
            cellBackView.layer.mask = maskLayer;
        }
            break;
        case BottomFillet:
        {
            UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cellBackView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(one, two)];
            CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
            maskLayer.frame = cellBackView.bounds;
            maskLayer.path = maskPath.CGPath;
            cellBackView.layer.mask = maskLayer;
        }
            break;
        case LeftFillet:
        {
            UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cellBackView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(one, two)];
            CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
            maskLayer.frame = cellBackView.bounds;
            maskLayer.path = maskPath.CGPath;
            cellBackView.layer.mask = maskLayer;
        }
            break;
        case RightFillet:
        {
            UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cellBackView.bounds byRoundingCorners:UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii:CGSizeMake(one, two)];
            CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
            maskLayer.frame = cellBackView.bounds;
            maskLayer.path = maskPath.CGPath;
            cellBackView.layer.mask = maskLayer;
        }
            break;
        case TopLeftFillet:
        {
            UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cellBackView.bounds byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(one, two)];
            CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
            maskLayer.frame = cellBackView.bounds;
            maskLayer.path = maskPath.CGPath;
            cellBackView.layer.mask = maskLayer;
        }
            break;
        case TopRightFillet:
        {
            UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cellBackView.bounds byRoundingCorners:UIRectCornerTopRight cornerRadii:CGSizeMake(one, two)];
            CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
            maskLayer.frame = cellBackView.bounds;
            maskLayer.path = maskPath.CGPath;
            cellBackView.layer.mask = maskLayer;
        }
            break;
        case BottomLeftFillet:
        {
            UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cellBackView.bounds byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(one, two)];
            CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
            maskLayer.frame = cellBackView.bounds;
            maskLayer.path = maskPath.CGPath;
            cellBackView.layer.mask = maskLayer;
        }
            break;
        case BottomRightFillet:
        {
            UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cellBackView.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(one, two)];
            CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
            maskLayer.frame = cellBackView.bounds;
            maskLayer.path = maskPath.CGPath;
            cellBackView.layer.mask = maskLayer;
        }
            break;
        default:
            break;
    }
    
    return cellBackView;
}

@end
